package StudyCode.Generic;

/**
 * @author lixiaoyao
 */
public class PairTest2 {
	public static void main(String[] args) {
		String[] words = {"Mary", "Had", "a", "Little", "Lamb"};
		Pair<String> mm = ArrayAlgTest2.minMax(words);
		System.out.println("min=" + mm.getFirst());
		System.out.println("max=" + mm.getSecond());
	}
}

class ArrayAlgTest2 {
	public static <T extends Comparable> Pair<T> minMax(T[] a) {
		if (a == null || a.length == 0) {
			return null;
		}
		T min = a[0];
		T max = a[0];
		for (int i = 1; i < a.length; i++) {
			if (min.compareTo(a[i]) > 0) {
				min = a[i];
			}
			if (max.compareTo(a[i]) < 0) {
				max = a[i];
			}
		}
		return new Pair<>(min, max);
	}
}



